const mysql = require('mysql')
const { MYSQL_CONFIG } = require('./config/db')
// 创建连接对象
const connection = mysql.createConnection(MYSQL_CONFIG)

// 开始连接
connection.connect()

// 执行sql语句
function execSql(sql, callback) {
  const newPromise = new Promise((resolve, reject) => {
    connection.query(sql, (err, result) => {
      if (err) {
        reject(err)
        return
      }
      resolve(result)
    })
  })

  return newPromise
}

connection.end()

module.exports = {
  execSql,
}
